<?php
Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . '/js/fileuploader/fileuploader.js', CClientScript::POS_HEAD);
Yii::app()->clientScript->registerCssFile(Yii::app()->baseUrl . '/js/fileuploader/fileuploader.css');
?>
<div class="flexform">
    <?php
    $form = $this->beginWidget('CActiveForm', array(
        'id' => 'subsite-category-form',
        'enableAjaxValidation' => false
            ));
    ?>

    <div class="row">
        <?php echo $form->labelEx($model, 'title'); ?>
        <?php echo $form->textField($model, 'title', array('size' => 30, 'maxlength' => 255, 'onblur' => 'setAlias(this)')); ?>
        <?php echo $form->error($model, 'title', array('class' => 'form-msg-error-advanced')); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'title_alias'); ?>
        <?php echo $form->textField($model, 'title_alias', array('size' => 30, 'maxlength' => 255)); ?>
        <?php echo $form->error($model, 'title_alias', array('class' => 'form-msg-error-advanced')); ?>
    </div>
    <div class="row">
        <?php echo $form->labelEx($model, 'pid'); ?>
        <?php echo $form->dropDownlist($model, 'pid', array('0' => '一级目录') + CHtml::listData(SubsiteCategory::model()->findAll('pid=0'), 'id', 'title')); ?>
        <?php echo $form->error($model, 'pid', array('class' => 'form-msg-error-advanced')); ?>
    </div>
    <div class="row">
        <?php echo $form->labelEx($model, 'menu'); ?>
        <?php echo $form->dropDownList($model, 'menu', array('1' => '是', '0' => '否')); ?>
        <?php echo $form->error($model, 'menu', array('class' => 'form-msg-error-advanced')); ?>
    </div>
    <div class="row">
        <?php echo $form->labelEx($model, 'product_model'); ?>
        <?php echo $form->dropDownlist($model, 'product_model', array('' => '', 'PRODUCT' => '产品类首页', 'ARCHIVE' => '资讯类首页') + array('产品' => Yii::app()->params->model_array) + array('资讯' => $this->model_info_array), array('onchange' => 'setInfosort(this)')); ?>
        <?php echo $form->error($model, 'product_model', array('class' => 'form-msg-error-advanced')); ?>
    </div>
    <div class="row" id="infosort-box" style="display: none;">
        <?php echo $form->labelEx($model, 'infosort_id'); ?>
        <?php echo $form->dropDownlist($model, 'infosort_id', array(0 => '', ) + CHtml::listData(Infosort::model()->findAll(), 'id', 'sort_name')); ?>
        <?php echo $form->error($model, 'infosort_id', array('class' => 'form-msg-error-advanced')); ?>
    </div>
    <div class="row">
        <?php echo $form->labelEx($model, 'game_id'); ?>
        <?php echo $form->dropDownlist($model, 'game_id', array('' => '') + ProductCategory::model()->getAllGameSelect()); ?>
        <?php echo $form->error($model, 'game_id', array('class' => 'form-msg-error-advanced')); ?>
    </div>
    <div class="row">
        <?php echo $form->labelEx($model, 'sort'); ?>
        <?php echo $form->textField($model, 'sort', array('size' => 11, 'maxlength' => 11)); ?>
        <?php echo $form->error($model, 'sort', array('class' => 'form-msg-error-advanced')); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'status'); ?>
        <?php echo $form->dropDownList($model, 'status', array('1' => '激活', '2' => '禁用')); ?>
        <?php echo $form->error($model, 'status', array('class' => 'form-msg-error-advanced')); ?>
    </div>
    <div class="row">
        <?php echo $form->labelEx($model, 'hot'); ?>
        <?php echo $form->dropDownList($model, 'hot', array(1 => '是', 0 => '否')); ?>
        <?php echo $form->error($model, 'hot', array('class' => 'form-msg-error-advanced')); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'thum'); ?>
        <?php echo $form->textField($model, 'thum', array('size' => 40, 'maxlength' => 255)); ?>
        <div id="upload-file" style="margin-left: 20px;float: left;">
            <noscript>          
            <p>Please enable JavaScript to use file uploader.</p>
            </noscript>   
        </div>
        <?php echo $form->error($model, 'thum', array('class' => 'form-msg-error-advanced')); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'page_title'); ?>
        <?php echo $form->textField($model, 'page_title', array('size' => 60, 'maxlength' => 255)); ?>
        <?php echo $form->error($model, 'page_title', array('class' => 'form-msg-error-advanced')); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'page_keywords'); ?>
        <?php echo $form->textField($model, 'page_keywords', array('size' => 60, 'maxlength' => 255)); ?>
        <?php echo $form->error($model, 'page_keywords', array('class' => 'form-msg-error-advanced')); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'page_description'); ?>
        <?php echo $form->textArea($model, 'page_description', array('rows' => 16, 'cols' => 80)); ?>
        <?php echo $form->error($model, 'page_description', array('class' => 'form-msg-error-advanced')); ?>
    </div>
    <div class="row">
        <?php echo $form->labelEx($model, 'info'); ?>
        <div style="padding-left: 130px;">
            <?php
            $this->widget('application.extensions.ckeditor.CKEditor', array(
                "model" => $model, # Data-Model
                "attribute" => 'info', # Attribute in the Data-Model
            ));
            ?>
        </div>
        <?php echo $form->error($model, 'info', array('class' => 'form-msg-error-advanced')); ?>
    </div>
    <div class="action">
        <?php echo CHtml::submitButton($model->isNewRecord ? '创建' : '保存'); ?>
    </div>
    <?php $this->endWidget(); ?>
</div><!-- form -->
<div class="clear"></div>
<script>
    function setInfosort(obj){
        if($(obj).val() == 'news'){
            $("#infosort-box").show();
        }else{
            $("#infosort-box").hide();
        }
    }
    function setAlias(obj){
        var av = $(obj).val();
        av = clearString(av);
        if($("#SubsiteCategory_title_alias").val() == ''){
            $("#SubsiteCategory_title_alias").val(av);
        }
        
    }
    //file upload
    var upimg='';
    var img_ext = "|jpg|jpeg|png|gif|bmp|";
    function createUploader(elementObj, setValueObj){//   elementObj: DIV, setValueObj: Will set value INPUT    
        var uploader = new qq.FileUploader({
            element: elementObj,
            action: '<?php echo Yii::app()->baseUrl; ?>/fileUpload.php',
            debug: false,
            showMessage: function(message){ alert(message); },
            allowedExtensions: ['jpg', 'jpeg', 'png', 'gif', 'bmp'],
            onProgress: function(id, fileName, loaded, total){
                //location.reload();
            },
            onComplete:function(id, fileName, responseJSON){
                if(responseJSON.success){
                    var dot_index = responseJSON.url.lastIndexOf('.');
                    var ext = responseJSON.url.substring(dot_index+1);
                    if(img_ext.indexOf(ext)>0){
                        //setValueObj.value=responseJSON.url;
                        setValueObj.val(responseJSON.url);
                    }
                }
            }
        });
        uploader.setParams({dir:"category_thumb"});
    }
    $(window).load(function(){
        createUploader(document.getElementById("upload-file"), $("#SubsiteCategory_thum"));
        if($("#SubsiteCategory_product_model").val() == 'news'){
            $("#infosort-box").show();
        }
    });
</script>